package de.hatraco.funderberg.blackjack.views;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.SwingConstants;

import de.hatraco.funderberg.blackjack.data.DataMISC;
import de.hatraco.funderberg.blackjack.data.GraphicsBlackJack;


public class StartDialog extends JDialog {
	
	//Singleton Pattern: Stellt sicher, dass nur eine Instanz von StartDialog existiert
	private static StartDialog instance = new StartDialog();

	public static StartDialog getInstance() {
		if(instance == null) {
			instance = new StartDialog();
		}
		return instance;
	}
	
	private JLabel bg_start;
	private JLabel welcome;
	private JLabel howmany1;
	private JLabel howmany2;
	
	private JButton button1;
	private JButton button2;
	private JButton button3;
	private JButton button4;	
    
	//private String link = DataMISC.LINKIMG;
    
    private GraphicsBlackJack img;
    
    private StartDialog() {
    	
    	//Instanziert GraphicsBlackJack (für die Bilder)
		this.img = GraphicsBlackJack.getInstance();
		
		//Legt die Größe des Fensters fest
		this.setSize(400,300);
		//Legt fest, dass die Größe nicht verändert werden kann
		this.setResizable(false);
		//Legt fest, dass das Fenster nicht über das "X" rechts oben geschlossen werden kann
		this.setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
		//Gibt dem Fenster ein BorderLayout
		this.setLayout(new BorderLayout());
		//Legt den Hintergrund fest
        bg_start = new JLabel(img.getBgstart());
        //Fügt den Hintergrund hinzu
        this.add(bg_start);
        //Gibt dem Hintergrund ein "leeres" Layout
        bg_start.setLayout(null);
        
        //Instanziert, Modifiziert und Positioniert die Elemente
        //JLabels
        welcome = new JLabel("Welcome to the");
        welcome.setFont(DataMISC.ARIAL_BOLD20);
		welcome.setForeground(Color.WHITE);
		welcome.setBounds(0, 35, 400, 25);
		welcome.setHorizontalAlignment(SwingConstants.CENTER);
		welcome.setVisible(false);
        
        howmany1 = new JLabel("Please select the");
        howmany1.setFont(DataMISC.ARIAL_BOLD20);
		howmany1.setForeground(Color.WHITE);
		howmany1.setBounds(0, 120, 400, 25);
		howmany1.setHorizontalAlignment(SwingConstants.CENTER);
		howmany1.setVisible(false);
        
        howmany2 = new JLabel("number of players:");
        howmany2.setFont(DataMISC.ARIAL_BOLD20);
		howmany2.setForeground(Color.WHITE);
		howmany2.setBounds(0, 145, 400, 25);
		howmany2.setHorizontalAlignment(SwingConstants.CENTER);
		howmany2.setVisible(false);
		
		//Buttons
		button1 = new JButton(img.getBt1());
		button2 = new JButton(img.getBt2());
		button3 = new JButton(img.getBt3());
		button4 = new JButton(img.getBt4());
		
		button1.setBounds(15, 200, 80, 40);
		button2.setBounds(110, 200, 80, 40);
		button3.setBounds(205, 200, 80, 40);
		button4.setBounds(300, 200, 80, 40);
		
		button1.setVisible(false);
		button2.setVisible(false);
		button3.setVisible(false);
		button4.setVisible(false);
		
		//Fügt die Elemente dem Hintergrund hinzu
		bg_start.add(welcome);
		bg_start.add(howmany1);
		bg_start.add(howmany2);
		bg_start.add(button1);
		bg_start.add(button2);
		bg_start.add(button3);
		bg_start.add(button4);		
	}
    
    //Definiert Listener für die Buttons
	public void setStartListener(ActionListener ae) {
		this.button1.addActionListener(ae);
		this.button2.addActionListener(ae);
		this.button3.addActionListener(ae);
		this.button4.addActionListener(ae);
	}

	public JButton getButton1() {
		return button1;
	}

	public void setButton1(JButton button1) {
		this.button1 = button1;
	}

	public JButton getButton2() {
		return button2;
	}

	public void setButton2(JButton button2) {
		this.button2 = button2;
	}

	public JButton getButton3() {
		return button3;
	}

	public void setButton3(JButton button3) {
		this.button3 = button3;
	}

	public JButton getButton4() {
		return button4;
	}

	public void setButton4(JButton button4) {
		this.button4 = button4;
	}

	public JLabel getBg_start() {
		return bg_start;
	}

	public void setBg_start(JLabel bg_start) {
		this.bg_start = bg_start;
	}

	public JLabel getWelcome() {
		return welcome;
	}

	public void setWelcome(JLabel welcome) {
		this.welcome = welcome;
	}

	public JLabel getHowmany1() {
		return howmany1;
	}

	public void setHowmany1(JLabel howmany1) {
		this.howmany1 = howmany1;
	}

	public JLabel getHowmany2() {
		return howmany2;
	}

	public void setHowmany2(JLabel howmany2) {
		this.howmany2 = howmany2;
	}
}
